package internal

import (
	"reflect"

	//"game-server/base"
	//"game-server/db"
	//"game-server/log"
	"game-server/msg"
	//"github.com/name5566/leaf/gate"
)


func init() {
	// 向当前模块（game 模块）注册 Hello 消息的消息处理函数 handleHello
	// 登陆消息注册
	handler(&msg.MsgLogin{}, handleLogin)
	// 创建房间消息注册
	handler(&msg.MsgCreateRoom{}, handleCreate)

	handler(&msg.MsgJoinRoom{},handleEnter)
	handler(&msg.MsgExitRoom{},handleExitRoom)
	handler(&msg.MsgChangeEgg{},handleChangeEgg)
	//handler(&msg.MsgChangeEgg{},handleChangeEgg)
	handler(&msg.MsgCancleRobot{},handleCancleRobot)
	handler(&msg.MsgUseItem{},handleUseItem)

	// 开始
	handler(&msg.MsgRoomStart{},handleRoomStart)
	handler(&msg.MsgChangeBird{},handleChangeBird)
	handler(&msg.MsgChangeName{},handleChangeName)
	handler(&msg.MsgOnRank{},handleOnRank)
	handler(&msg.MsgOnFriendIngo{},handleOnFriendIngo)

	handler(&msg.MsgUseItemResult{},handleUseItemResult)


}

func handler(m interface{}, h interface{}) {
	skeleton.RegisterChanRPC(reflect.TypeOf(m), h)
}
//
//// 战绩查询
//func handleBattleResult(args []interface{}) {
//	message := args[0].(*msg.MsgBattleResult)
//	conn := args[1].(gate.Agent)
//	userId := message.GetUserId()
//	roomNo := message.GetRoomNo()
//	roundId := message.GetRoundId()
//	log.Debug("BattleResult: userId = ", userId)
//	log.Debug("BattleResult: roomNo = ", roomNo)
//	log.Debug("BattleResult: roundId = ", roundId)
//
//	skeleton.AsynCall(db.ChanRPC, "BattleResult", args[0], func(ret interface{}, err error) {
//		if err != nil {
//			log.Debug("BattleResult: err = ", err)
//		} else {
//			conn.WriteMsg(ret)
//		}
//	})
//}
//
//// 获取位置信息
//func handleLocation(args []interface{}) {
//	message := args[0].(*msg.MsgLocation)
//
//	userId := message.GetUserId()
//	geoPoint := message.GetGeoPoint()
//	if geoPoint != "" && base.IsExist("user", userId) {
//		userInfo := base.Get("user", userId).(base.UserInfo)
//		userInfo.GeoPoint = geoPoint
//		base.Put("user", userId, userInfo)
//		log.Info("获取位置信息成功 === ", message.GetGeoPoint())
//	}
//}